#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5,M=1e5+5;
ll t,n,m,L,V,d[N],v[N],a[N],p[M];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n>>m>>L>>V;
        ll cnt=0;
        for(int i=1;i<=n;i++) cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++) cin>>p[i];
        sort(p+1,p+m+1);
        for(int i=1;i<=n;i++){
            if(a[i]==0) if(v[i]>V&&d[i]<=p[m]) cnt++;
            if(a[i]>0){
                ll hc=V*V-v[i]*v[i],zxr=2*a[i];
                if(v[i]>V){
                    if(d[i]<=p[m]) cnt++;
                }
                else{
                    if((p[m]-d[i])*zxr>hc) cnt++;
                }
            }
        }
        int flagA=1,flagB=1;
        for(int i=1;i<=n;i++){
            if(a[i]!=0) flagA=0;
            if(a[i]<=0) flagB=0;
        }
        if(flagA){
            cout<<cnt<<" ";
            if(cnt==0) cout<<m<<endl;
            else cout<<m-1<<endl;
        }
        if(flagB){
            cout<<cnt<<" ";
            if(cnt==0) cout<<m<<endl;
            else cout<<m-1<<endl;
        }
    }
    return 0;
}
